import requests
import re
import json
import time
from requests.exceptions import RequestException

def get_onePage(url):
    headers = {
        'User-Agent' :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
                      ' Chrome/68.0.3423.2 Safari/537.36'
        }
    response = requests.get(url,headers=headers)
    if response.status_code == 200:
        return response.text
    return None

def main(offset):
    url = "http://maoyan.com/board/4?offset="+str(offset)
    html = get_onePage(url)
    for item in parse_one_page(html):
        print(item)

def parse_one_page(html):
    pattern = re.compile('<dd>.*?board-index.*?>(\d+)</i>.*?data-src="(.*?)".*?name">', re.S)
    items = re.findall(pattern,html)
    print(items)

if __name__ =='__main__':
    for i in range(10):
        main(offset=1*10)
        time.sleep(1)
